using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.IO;

namespace ReviewIt
{
    class Program
    {
        private static ArrayList arr = new ArrayList();
        private static int resxTmp = 0;
        private static int lowTmp;
        private static int highTmp;
        private static int inventory;
        private static int ratioTmp;

        static void Main(string[] args)
        {
            if (File.Exists(@"ReviewIt.txt")) File.Delete(@"ReviewIt.txt");
            String rawData = args[0];
            //Console.WriteLine(rawData);
            //LogUtil.writeLog("ss");
            char[] splitter = new char[] { ',' };
            string[] strlist = rawData.Split(splitter, StringSplitOptions.RemoveEmptyEntries);
            foreach (string tmp in strlist)
            {
                int resx = int.Parse(tmp);
                if(resxTmp != resx)
                {
                    arr.Add(resx);
                    LogUtil.writeLog(resx + ",");
                    if (arr.Count > 3)
                    {
                        int t1 = (int) arr[arr.Count - 1];
                        int t2 = (int) arr[arr.Count - 2];
                        int t3 = (int) arr[arr.Count - 3];
                        int t4 = (int) arr[arr.Count - 4];

                        #region kk
                        if (t4 >= 0 && t3 < 0 && t2 < 0 && t1 < 0)
                        {
                            highTmp = 0;
                            inventory = 1;
                            LogUtil.writeLog("kk");
                        } 
                        #endregion

                        #region dk
                        if (t4 <= 0 && t3 > 0 && t2 > 0 && t1 > 0)
                        {
                            lowTmp = 0;
                            inventory = 1;
                            LogUtil.writeLog("dk");
                        } 
                        #endregion

                        #region KP
                        if (t3 < 0 && t2 < 0 && t1 < 0 && Math.Abs(t1) < Math.Abs(t2) && Math.Abs(t3) < Math.Abs(t2))
                        {
                            if (lowTmp < Math.Abs(t2))
                            {
                                lowTmp = t2;
                                if (ratioTmp < Math.Abs(t2))
                                {
                                    ratioTmp = Convert.ToInt32(Math.Abs(t2 * 0.618));
                                }
                                LogUtil.writeLog("["+ratioTmp+"],");
                            }
                        }

                        
                        if (lowTmp < 0 && inventory == 1 && t1 < 0 && t2 < 0 && t3 < 0)
                        {
                            if (Math.Abs(lowTmp) <= ratioTmp)
                            {
                                LogUtil.writeLog("kp");
                                lowTmp = 0;
                                inventory = 0;
                            }
                            else
                            {
                                if (t1 < 0 && t2 < 0 && t3 < 0 && Math.Abs(t1) < ratioTmp && Math.Abs(t2) < ratioTmp && Math.Abs(t3) < ratioTmp)
                                {
                                    LogUtil.writeLog("kp");
                                    lowTmp = 0;
                                    inventory = 0;
                                }
                            }
                        } 
                        #endregion

                        #region dp
                        if (t3 > 0 && t2 > 0 && t1 > 0 && t1 < t2 && t3 < t2)
                        {
                            if (highTmp < t2)
                            {
                                highTmp = t2;
                                if (ratioTmp < t2)
                                {
                                    ratioTmp = Convert.ToInt32(t2 * 0.618);
                                }
                                LogUtil.writeLog("[" + ratioTmp + "],");
                            }
                        }

                        if (highTmp > 0 && inventory == 1 && t1 > 0 && t2 > 0 && t3 > 0)
                        {
                            if (highTmp <= ratioTmp)
                            {
                                LogUtil.writeLog("dp");
                                highTmp = 0;
                                inventory = 0;
                            }
                            else
                            {
                                if (t1 < ratioTmp && t2 < ratioTmp && t3 < ratioTmp)
                                {
                                    LogUtil.writeLog("dp");
                                    highTmp = 0;
                                    inventory = 0;
                                }
                            }
                        } 
                        #endregion                     
                    }
                    resxTmp = resx;
                }
            }
        }
    }
}
